/*
 * ******************************************************************************
 *   Copyright (c) 2013-2014 Gabriele Mariotti.
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 *  *****************************************************************************
 */

package it.gmariotti.cardslib.demo.ui.widget;

import it.gmariotti.cardslib.demo.ResourceTable;
import it.gmariotti.cardslib.library.Constants;
import ohos.agp.components.AttrSet;
import ohos.agp.components.Component;
import ohos.agp.components.StackLayout;
import ohos.agp.render.Canvas;
import ohos.agp.render.Paint;
import ohos.agp.utils.Color;
import ohos.app.Context;
import ohos.global.resource.NotExistException;
import ohos.global.resource.WrongTypeException;
import ohos.hiviewdfx.HiLog;

import java.io.IOException;


/**
 * A view that draws fancy horizontal lines to frame it's content
 */
public class HashtagView extends StackLayout implements Component.DrawTask {

    private static final int LINE_COLOUR = 0x59ffffff;

    private Paint mLinesPaint;
    private float[] mLinePoints;

    public HashtagView(Context context) {
        this(context, null, "0");
    }

    public HashtagView(Context context, AttrSet attrs) {
        this(context, attrs, "0");
    }

    public HashtagView(Context context, AttrSet attrs, String defStyle) {
        super(context, attrs, defStyle);
        mLinesPaint = new Paint();
        mLinesPaint.setAntiAlias(true);
        mLinesPaint.setColor(new Color(LINE_COLOUR));
        mLinesPaint.setStyle(Paint.Style.STROKE_STYLE);
        try {
            mLinesPaint.setStrokeWidth(context.getResourceManager().getElement(
                    ResourceTable.Float_hashtag_line_height).getFloat());
        } catch (Exception e) {
             HiLog.error(Constants.LABEL_LOG,e.toString());
        }

        addDrawTask(this);
    }
    //todo no such method
//    @Override
//    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
//        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
//
//        // calculate points for two horizontal lines spaced at 1/3 & 2/3 of the height, occupying
//        // 2/3 of the width (centered).
//        final int thirdHeight = getMeasuredHeight() / 3;
//        final int sixthWidth = getMeasuredWidth() / 6;
//        mLinePoints = new float[]{
//                // line 1
//                sixthWidth, thirdHeight, 5 * sixthWidth, thirdHeight,
//                // line 2
//                sixthWidth, 2 * thirdHeight, 5 * sixthWidth, 2 * thirdHeight};
//    }


    @Override
    public void onDraw(Component component, Canvas canvas) {
        canvas.drawLines(mLinePoints, mLinesPaint);
    }
}
